<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vue</title>

    <style>

    </style>

</head>
<body>
<!--实现输入框实时同步-->
<div id="app">
    <input type="text" v-model="firstname"> +
    <input type="text" v-model="lastname"> =
    <input type="text" v-model="fullname">

</div>


<script src="https://unpkg.com/vue/dist/vue.js"></script>
<script>
    let vm = new Vue({
        el: "#app",
        data: {
            firstname: '',
            lastname: '',
            fullname: ''
        },
        methods: {
        },
        // watch事件可以监听data数据变化，提供变化回调
        // @keyup事件只能监听基本元素的事件，不能监听类似路由地址这类的东西，但是watch可以
        watch: {
            // 监听firstname变化, 有两个参数，变化后的值和变化前的值
            firstname: function (newVal, oldVal) {
                this.fullname = newVal + this.lastname
            },
            lastname: function (newVal) {
                this.fullname = this.firstname + newVal
            }
        }
    })

</script>
</body>
</html>
